<?php

	/*
	 * ThinkSAAS APP入口
	 * @copyright (c) 2010-3000 ThinkSAAS All Rights Reserved
	 * @code by QINIAO
	 * @Email:qiniao@vip.qq.com
	 */

	/*
	 *定义所需路径
	 */

	define('__APP__',THINKAPP.'/'.$app);

	/*
	 *定义APP ACTION,APP MODEL,APP ADMIN,APP VIEW,APP INC
	 */

	define('__APP_ACTION__',__APP__.'/action');

	define('__APP_MODEL__',__APP__.'/model');

	define('__APP_ADMIN__',__APP__.'/action/admin');

	define('__APP_API__',__APP__.'/action/api');

	/*
	 *ADMIN
	 */
	define('PUB_ADMIN_HTML',THINKAPP.'/admin/view/html');

	/*
	 *APP模板CSS,IMG,
	 */
	$_APP['tpl']	= array(

		'css'	=> 'app/'.$app.'/view/skins/default/style',
		'img'	=> 'app/'.$app.'/view/skins/default/images',
		'inc'	=> 'app/'.$app.'/inc',

	);

	/*
	 *后台(madmin)模版CSS,IMG
	 */

	$_APP['admin']	= array(
		'css'	=> '/app/admin/view/skins/default/style',
		'img'	=> '/app/admin/view/skins/default/images',
		'inc'	=> '/app/admin/inc/',
	);

	/*
	 *加载APP应用首页和配置文件
	 */

	if(is_file(__APP_ACTION__.'/'.$ac.'.php')){


		/*
		 *加载APP配置文件
		 */

		require_once __APP__.'/config.php';

		/*
		 * 连接数据库
		 */

		require_once THINKSAAS.'/public/sql/mysql.php';
		$DB	= new MySql($_DB['host'],$_DB['user'],$_DB['pwd'],$_DB['name']);

		/*
		 *加载APP数据库操作类并建立对象
		 */

		require_once __APP_MODEL__.'/class.'.$app.'.php';

		$new[$app] = new $app($DB);


		/*
		 *装载Smarty模板引擎
		 */

		require_once(THINKDATA.'/class/smarty/Smarty.class.php');

		$tpl = new smarty;

		$tpl->template_dir = __APP__.'/view/html/';
		$tpl->compile_dir = THINKDATA.'/templates_c/'.$app.'/';

		$tpl->assign('_SITE',$_SITE);
		$tpl->assign('_APP',$_APP);
		$tpl->assign('_USER',$_USER);
		$tpl->assign('_URL',$_URL);
		$tpl->assign('_SOFT',$_SOFT);

		//没有图片
		$tpl->assign('_NOIMG',$_NOIMG);

		$tpl->assign('app',$app);


		/*
		 *运行统计结束
		 */

		$time_end = getmicrotime();
		$runTime = $time_end - $time_start;

		$tpl->assign('runTime',$runTime);

		/*
		 *开始执行APP
		 */

		require_once __APP_ACTION__.'/'.$ac.'.php';

	}else{

		qiMsg('sorry:no results!');
		exit;

	}

